package cn.tansanqinger.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tansanqinger.dao.sql.impl.MenuSqlDaoImpl;
import cn.tansanqinger.pojo.Menu;
import cn.tansanqinger.service.IMenuService;
import cn.tansanqinger.util.Encoder_Dispose;

@Service
public class MenuServiceImpl implements IMenuService{

	@Autowired
	private MenuSqlDaoImpl menuDao;
	
	@Override
	public List<Menu> selectMenuAll() {
		return menuDao.selectMenuAll();
	}

	@Override
	public List<Menu> selectFirstMenuAll() {
		return menuDao.selectFirstMenuAll();
	}

	@Override
	public List<Menu> selectNextMenuAll(String parentId) {
		return menuDao.selectNextMenuAll(parentId);
	}

	@Override
	public void deleteMenuById(String menuId) {
		menuDao.deleteMenuById(Integer.parseInt(menuId));
	}

	@Override
	public void updataMenuIcon(Integer menuId, String menuIcon) {
		Menu menu = menuDao.getMenuById(menuId);
		menu.setMenuIcon(menuIcon);
		menuDao.updataMenuIcon(menu);
	}

	@Override
	public Menu getMenuById(Integer menuId) {
		return menuDao.getMenuById(menuId);
	}

	@Override
	public void updataMenuAll(Menu menu) {
		if(!Encoder_Dispose.isNull(menu.getParentId())) {
			menu.setParentId("0");
		}
		if(!"0".equals(menu.getParentId())) {
			menu.setMenuType("");
		}
		menuDao.updateMenuAll(menu);
	}

	@Override
	public void saveMenu(Menu menu) {
		if(!Encoder_Dispose.isNull(menu.getParentId())) {
			menu.setParentId("0");
		}
		if(!"0".equals(menu.getParentId())) {
			menu.setMenuType("");
		}
		menuDao.saveMenu(menu);
	}

	@Override
	public int selectIdCount(int parentId) {
		return menuDao.selectIdCount(parentId);
	}
	
}
